#include<iostream>
#include<vector>

#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/rotating_file_sink.h"

using namespace std;

namespace {


void Handle() {

    spdlog::info("Welcome to spdlog version {}.{}.{}  !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);

    spdlog::flush_every(std::chrono::seconds(1));
    spdlog::flush_on(spdlog::level::debug);

    try {
        // Create basic file logger (not rotated)
        auto my_logger = spdlog::basic_logger_mt("basic_logger", "logs/basic.txt");
        // create a file rotating logger with 1kb size max and 3 rotated files
        auto file_logger = spdlog::rotating_logger_mt("file_logger", "logs/myfilename", 1024, 3);

        my_logger->info("This is a basic logger.");

        for (int i = 0; i < 1024 * 5; i++)
            file_logger->info("This is a rotating logger: #{}", i);
    } catch (const spdlog::spdlog_ex& ex) {
        std::cout << "Log initialization failed: " << ex.what() << std::endl;
    }

}
}

void HandleSpdlog() {
    Handle();
}